<template>
  <el-dialog :close-on-click-modal="false" title="导出标签" width="600"
             draggable v-model="visible">
    <el-form :model="form" :rules="dataRules" label-width="90px" ref="dataFormRef" v-loading="loading">
      <el-form-item label="学校" prop="schoolId">
        <el-select v-model="form.schoolId" placeholder="请选择学校" style="width: 100%" @change="(item: any)=> getGradeList(item)">
          <el-option v-for="item in data.schoolList" :key="item.id" :label="item.schoolName" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-date-picker
            v-model="form.date"
            type="date"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            placeholder="请选择日期"
        />
      </el-form-item>
    </el-form>
    <template #footer>
			<span class="dialog-footer">
				<el-button @click="visible = false">{{ $t('common.cancelButtonText') }}</el-button>
				<el-button @click="onSubmit" type="primary" :disabled="loading">导出</el-button>
			</span>
    </template>
  </el-dialog>
</template>

<script lang="ts" name="systemRoleDialog" setup>
import {rule} from '/src/utils/validate';
import {deptTree} from '/src/api/admin/dept';
import {useMessage} from '/src/hooks/message';
import {addObj, getObj, putObj} from '/src/api/school/student';
import {useI18n} from 'vue-i18n';
import {listAll as listAllSchool} from "/@/api/school/school";
import {listAll as listAllGrade} from "/@/api/school/grade";
import {listAll as listAllClasses} from "/@/api/school/classes";

import other from '/@/utils/other';
// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh']);

const {t} = useI18n();

// 定义变量内容
const dataFormRef = ref();
const deptTreeRef = ref();
const visible = ref(false);
const loading = ref(false);

// 提交表单数据
const form = reactive({
  id: '',
  schoolId: '',
  gradeId: '',
  classesId: '',
  studentId: '',
  name: '',
  parentId: ''
});

// 页面对应元数据
const dataForm = reactive({
  deptData: [],
  checkedDsScope: [],
  deptProps: {
    children: 'children',
    label: 'name',
    value: 'id',
  },
});

const data = reactive({
  schoolList: [],
  gradeList:[],
  classesList:[]
})

const getSchoolList = async ()=>{
  data.gradeList = [];
  data.schoolList = [];
  data.classesList = [];
  const resp = await listAllSchool();
  data.schoolList = resp.data
}

const getGradeList = async (schoolId: string)=>{
  data.gradeList = [];
  data.classesList = [];
  const resp = await listAllGrade({schoolId});
  data.gradeList = resp.data
}

const getClassesList = async (gradeId: string)=>{
  data.classesList = [];
  const resp = await listAllClasses({gradeId});
  data.classesList = resp.data
}


// 定义校验规则
const dataRules = ref({
  schoolId: [
    {required: true, message: '学校不能为空', trigger: 'blur'},
  ],
  date: [
    {required: true, message: '时间不能为空', trigger: 'blur'},
  ]
});

// 打开弹窗
const openDialog = (id: string) => {
  visible.value = true;
  form.id = '';
  getSchoolList();
  nextTick(() => {
    dataFormRef.value.resetFields();
  });

};

// 提交
const onSubmit = async () => {
  const valid = await dataFormRef.value.validate().catch(() => {
  });
  if (!valid) return false;
  other.downBlobFile("/admin/studentCombo/dowloadTag", form, "标签.docx");

};



// 暴露变量
defineExpose({
  openDialog,
});
</script>
